integer function onebit(c)
    character(len=1) :: c
    select case(c)
        case('0')
            onebit=0
        case('1')
            onebit=1
        case('2')
            onebit=2
        case('3')
            onebit=3
        case('4')
            onebit=4
        case('5')
            onebit=5
        case('6')
            onebit=6
        case('7')
            onebit=7
        case('8')
            onebit=8
        case('9')
            onebit=9
    end select
end function onebit
!转换为整型
integer function str2int(n)
    interface
        function onebit(c)
            character(len=1) :: c
            integer :: onebit
        end function
    end interface
    character(len=100) :: n,t
    integer :: l,i
    t=adjustl(n)
    l=len_trim(t)
    str2int=0
    do i=1,l
        str2int = str2int*10 + onebit( t(i:i) )
    end do
end function str2int

!转换为实型
function str2real(x)
    implicit none
    interface
        function str2int(n)
            character(len=100) :: n
            integer :: str2int
        end function
    end interface
    character(len=100) :: x,t,t1
    real :: str2real
    integer :: p,l
    !integer,external :: str2int
    t=adjustl(x)
    l=len_trim(t)
    p=index(t,'.')
    t1(1:)=t(1:p-1)//t(p+1:l)
    str2real=str2int( t1 )*0.1**(l-p)
end function str2real

program main
    implicit none
    interface
        function str2int(n)
            character(len=100) :: n
            integer str2int
        end function
        function str2real(x)
            character(len=100) :: x
            real str2real
        end function
    end interface
    character(len=100) :: s1='23456'
    character(len=100) :: s2='75.8'
    write(*,*) 's1:',str2int(s1)
    write(*,*) 's2:',str2real(s2)
end program
